﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Twitch_Viewer {
    public partial class Viewer : Form {
        public Viewer() {
            InitializeComponent();
            this.FormClosing += formClosing;
        }

        private void openNewStreamToolStripMenuItem_Click(object sender, EventArgs e) {
            Ask ask = new Ask();
            ask.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
            Process.GetCurrentProcess().Kill();
        }

        private void formClosing(object sender, EventArgs e) {
            int count = 0;
            for (int i = 0; i < Application.OpenForms.Count; i++) {
                if(Application.OpenForms[i].Visible == true) {
                    count++;   
                }

                if (Application.OpenForms[i].Visible == false) {
                    count--;
                }
            }

            if (count <= 0) {
                Process.GetCurrentProcess().Kill();
            }
        }
    }
}
